package com.stx.friends.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.BeanUtils;
import com.stx.friends.dao.UserDao;
import com.stx.friends.entity.UserEntity;
import com.stx.friends.service.UserService;
import com.stx.friends.vo.UserVo;
import com.sun.org.apache.regexp.internal.recompile;

public class UserServiceImpl implements UserService {

	private UserDao dao = null;

	public List<UserVo> list(UserVo criteria) {

		List<UserVo> voList = new ArrayList<UserVo>();

		List<UserEntity> entityList = dao.list(criteria);

		for (UserEntity entity : entityList) {

			UserVo vo = new UserVo();

			// 对象属性值拷贝 entity => vo
			BeanUtils.copyProperties(entity, vo);

			voList.add(vo);

		}

		return voList;
	}
	@Override
	public List<UserVo> listByUid(String wrxUid) {
		List<UserVo> voList = new ArrayList<UserVo>();

		List<UserEntity> entityList = dao.listByUid(wrxUid);

		for (UserEntity entity : entityList) {

			UserVo vo = new UserVo();

			// 对象属性值拷贝 entity => vo
			BeanUtils.copyProperties(entity, vo);

			voList.add(vo);

		}

		return voList;
	}
	@Override
	public void delUser(String wrxUid) {
		
		dao.delUser(wrxUid);

	}
	@Override
	public void addUser(UserVo user) {
		
		dao.addUser(user);
		
	}

	public void setDao(UserDao dao) {
		this.dao = dao;
	}

	@Override
	public UserVo getUserById(String id) {
		UserEntity entity=new UserEntity();
		UserVo vo=new UserVo();
		System.out.println("``"+id);
		entity= this.dao.getUserById(id);
		BeanUtils.copyProperties(entity, vo);
		return vo;
		
	}

	@Override
	public UserVo findUserByUnameAndPassword(String username, String password) {
		UserEntity userentity=dao.findUserByUnameAndPassword(username, password);
		UserVo uservo = null;

		if (userentity != null) {
			uservo = new UserVo();
			BeanUtils.copyProperties(userentity, uservo);
		}

		return uservo;
		
		
	}

	@Override
	public String getIdByUname(String uname) {
		
		return this.dao.getIdByUname(uname);
	}
	@Override
	public void updateUser(UserVo criteria) {
		this.dao.updateUser(criteria);
		
	}

	



}
